package org.applet.game.app.rpg.scene;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;

import org.applet.game.app.rpg.SimpleSprite8D;
import org.applet.game.app.rpg.Sprite;
import org.applet.game.app.rpg.magic.FreeTargetMagic;
import org.applet.game.app.rpg.magic.Magic;
import org.applet.game.app.rpg.resource.MagicResource;
import org.applet.game.app.rpg.widgets.MagicSelector;
import org.applet.game.app.rpg.widgets.MapNavigator;
import org.applet.game.app.rpg.widgets.ParcelPanel;
import org.applet.game.app.rpg.widgets.SceneToolbar;
import org.applet.game.framework.core.Scene;
import org.applet.game.framework.util.TimerUtil;

public class JXScene extends Scene {

	MagicSelector selector;
	SceneToolbar toolbar;
	
	@Override
	public void init() {
		toolbar = new SceneToolbar();
		toolbar.setName("testxx");
		add(toolbar);
		buttomMiddle(toolbar);

		MapNavigator small = new MapNavigator(this, 245, 160);
		add(small);
		rightTop(small);
		
		super.init();
	}
	
	public void showItemBox()
	{
		ParcelPanel parcel = new ParcelPanel();
		parcel.setName("testyy");
		add(parcel);
		parcel.setLocation(10, 10);
	}
	
	public void showMagicSelector(int x, int y)
	{
		if(selector==null)
		{
			selector = new MagicSelector();
			this.add(selector);
			selector.setLocation(x, y);
		}
		else
			selector.setVisible(true);
	}
	
	public void hideMagicSelector()
	{
		if(selector!=null)
			selector.setVisible(true);
	}
	
	int rightMagic = 0;
	public void selectMagic(int magicIndex)
	{
		rightMagic = magicIndex;
		toolbar.setRightButtonImage(MagicResource.getMagicTitle(magicIndex));
		magic = new FreeTargetMagic(magicIndex);
		magic.magicer = getHero();
		magic.setScene(this);
		magic.setBodyFrames("0");
		((SimpleSprite8D)getHero()).setCurrentMagic(magic);
	}
	
	Magic magic;
	
	@Override
	public void render(Graphics2D painter, ImageObserver observer) {
		super.render(painter, observer);
		if(magic!=null)
			magic.render(painter, observer);
	}
}
